package com.rt.tmpt.controller.springmvc.admin;


import com.google.gson.Gson;
import com.rt.tmpt.dto.A2UserDesktopDto;
import com.rt.tmpt.dto.A2UserDto;
import com.rt.tmpt.dto.ConstantDto;
import com.rt.tmpt.dto.Result;
import com.rt.tmpt.service.ISecurityV2Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@ApiIgnore
@Controller
@RequestMapping("/admin123/desktop")
@Slf4j
public class DesktopAction {

    @Resource
    private ISecurityV2Service securityV2Service;

    public String addMenu2Desktop(String menuId, String href, String text,
                                  HttpServletRequest request, HttpServletResponse response) {
        Result result = new Result();
        try {
            HttpSession session = request.getSession();
            A2UserDto userDto = (A2UserDto) session.getAttribute(ConstantDto.MagSystemDtoSession);
            long userId = userDto.getId();

            A2UserDesktopDto desktopDto = new A2UserDesktopDto();
            //desktopDto.setMenu1Id(menu1Id);
            //desktopDto.setMenu2Id(menu2Id);
            desktopDto.setMenuId(menuId);
            desktopDto.setHeight(500);
            desktopDto.setWidth(800);
            desktopDto.setHref(href);
            desktopDto.setText(text);
            desktopDto.setIcon("images/icon3d/005.png");

            System.out.println("----userId" + userId);
            securityV2Service.addMenu2Desktop(userId, desktopDto);
            result.success();
        } catch (Exception e) {
            e.printStackTrace();
            result.fault(e.getLocalizedMessage());
        }
        return new Gson().toJson(result.getMap());
    }


    public String removeMenu2Desktop(String desktopItemId) {
        Result result = new Result();
        try {
            securityV2Service.removeMenu2Desktop(Long.parseLong(desktopItemId));
            result.success();
        } catch (Exception e) {
            result.fault(e.getLocalizedMessage());
            e.printStackTrace();
        }
        return new Gson().toJson(result.getMap());
    }


}
